package com.demo.controller.api1;

import com.demo.dto.CommonDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;


/**
 * @author yexi
 */
@RestController
@RequestMapping("test")
@Api(tags = {"这是测试一", "这是测试一的另一个标签"})
public class DemoController {

    @ApiOperation(value = "测试接口", notes = "相关描述")
    // swagger2生成测试接口时的解释和生成逻辑
    @ApiImplicitParam(name = "params", value = "对该参数想添加的内容，一般用来介绍参数是什么", paramType = "body", required = true, defaultValue = "{\n" +
            "  \"参数2\": \"值2\",\n" +
            "  \"参数1\": \"值1\"\n" +
            "}")
    @PostMapping("/demo")
    public HashMap<String, Object> demo(@RequestBody Map<String, Object> params) {
        System.out.println(params);
        HashMap<String, Object> result = new HashMap<>();
        result.put("参数1", "值1");
        result.put("参数2", "值2");
        return result;
    }


    @ApiOperation(value = "测试接口2", notes = "相关描述2")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id:id", required = true, dataType = "Long", paramType = "path", defaultValue = "13"),
            @ApiImplicitParam(name = "name", value = "name:名称", required = true, dataType = "string", paramType = "query", defaultValue = "test")
    })
    @PostMapping("/demo2/{id}")
    public HashMap<String, Object> demo2(String name, @PathVariable("id") Long id) {
        System.out.println("名称: " + name + " id: " + id);
        HashMap<String, Object> result = new HashMap<>();
        result.put("参数1", "值1");
        result.put("参数2", "值2");
        return result;
    }

    @PostMapping("/demo3")
    public HashMap<String, Object> demo3(@RequestBody CommonDto commonDto) {
        System.out.println(commonDto);
        HashMap<String, Object> result = new HashMap<>();
        result.put("参数1", "值1");
        result.put("参数2", "值2");
        return result;
    }

}
